<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <link href="${ctxPath!}/layui/css/layui.css" rel="stylesheet" type="text/css">
    <% include("/templates/common/dialog.html"){} %>
</head>
<div style="padding:10px 50px 10px 10px">
    <form id="contractForm" method="post" action="${ctxPath!}/sys/contract/edit" class="layui-form layui-row">
        <div style="margin-bottom:20px;font-size:14px;border-bottom:1px solid #ccc; padding-bottom: 5px;">合同信息</div>
        <input type="hidden" name="id" value="${contract.id}"/>
        <br>
        <div class="layui-form-item">
            <label class="layui-form-label">客户</label>
            <div class="layui-input-block">
                <select name="userId" id="userId" lay-search>
                    <option value=""></option>
                    <%
                    for(user in users!){
                    %>
                    <option value="${user.id}" ${contract.userId == user.id ? "selected" : ""}>${user.username}</option>
                    <%
                    }
                    %>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">育婴师</label>
            <div class="layui-input-block">
                <select name="nurseryTeacherId" id="nurseryTeacherId" lay-search>
                    <option value=""></option>
                    <%
                    for(nurseryTeacher in nurseryTeachers!){
                    %>
                    <option value="${nurseryTeacher.id}" ${contract.nurseryTeacherId == nurseryTeacher.id ? "selected" : ""}>${nurseryTeacher.username}</option>
                    <%
                    }
                    %>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">育婴顾问</label>
            <div class="layui-input-block">
                <select name="nurseryConsultantId" id="nurseryConsultantId" lay-search>
                    <option value=""></option>
                    <%
                    for(nurseryConsultant in nurseryConsultants!){
                    %>
                    <option value="${nurseryConsultant.id}" ${contract.nurseryConsultantId == nurseryConsultant.id ? "selected" : ""}>${nurseryConsultant.username}</option>
                    <%
                    }
                    %>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">预产期</label>
            <div class="layui-input-block">
                <input class="layui-input" type="text" id="dueDate" name="dueDate"  value="${contract.dueDate!,dateFormat="yyyy-MM-dd"}" lay-verify="required" readonly/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><nobr>预计签约时间</nobr></label>
            <div class="layui-input-block">
                <input class="layui-input" type="text" id="signDate" name="signDate"  value="${contract.signDate!,dateFormat="yyyy-MM-dd"}" lay-verify="required" readonly/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><nobr>服务开始日期</nobr></label>
            <div class="layui-input-block">
                <input class="layui-input" type="text" id="startDate" name="startDate"  value="${contract.startDate!,dateFormat="yyyy-MM-dd"}" lay-verify="required" readonly/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><nobr>服务结束日期</nobr></label>
            <div class="layui-input-block">
                <input class="layui-input" type="text" id="endDate" name="endDate"  value="${contract.endDate!,dateFormat="yyyy-MM-dd"}" lay-verify="required" readonly/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">住址</label>
            <div class="layui-input-block">
                <input class="layui-input" type="text" name="address"  value="${contract.address!}" lay-verify="required" />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">合同金额</label>
            <div class="layui-input-block">
                <input class="layui-input" type="text" name="money"  value="${contract.money!}" lay-verify="required" />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">合同状态</label>
            <div class="layui-input-block">
                <select name="status" id="status" lay-filter="status">
                    <option value=""></option>
                    <option value="1" ${contract.status == true ? "selected" : ""}>正在进行</option>
                    <option value="0" ${contract.status == false ? "selected" : ""}>已结束</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button id="submitButton" class="layui-btn" lay-submit lay-filter="*">保存</button>
                <button type="button" class="layui-btn layui-btn-primary" onclick="closeAll()">取消</button>
            </div>
        </div>
    </form>
</div>
<script src="${ctxPath!}/jquery/jquery.min.js"></script>
<script src="${ctxPath!}/layui/layui.js"></script>
<script src="${ctxPath!}/jqgrid/jquery.jqGrid.minffe4.js?0820"></script>
<script src="${ctxPath!}/jqgrid/myjqGrid.js?v=1.0.1"></script>
<script type="text/javascript">
    layui.use(['form','laydate'], function(){
        var form = layui.form;
        var laydate = layui.laydate;

        //执行一个laydate实例
        laydate.render({
            elem: '#dueDate' //指定元素
        });
        laydate.render({
            elem: '#signDate' //指定元素
        });
        laydate.render({
            elem: '#startDate' //指定元素
        });
        laydate.render({
            elem: '#endDate' //指定元素
        });
        form.on('submit(*)', function(data){
            $.post($("#contractForm").attr("action"), $("#contractForm").serialize(), function(data){
                if(data.status == 200){
                    layer.alert(data.msg, {
                        icon: 1,
                        skin: 'layer-ext-moon'
                    },function () {
                        parent.myJqGrid.reloadGrid({});
                        parent.layer.closeAll();
                    });
                }else{
                    layer.alert(data.msg, {
                        icon: 2,
                        skin: 'layer-ext-moon'
                    });
                }
            });
            return false; //阻止表单跳转。
        });
        form.on('select(orgId)', function(data){
            console.log(data.elem); //得到select原始DOM对象
            console.log(data.value); //得到被选中的值
            console.log(data.othis); //得到美化后的DOM对象
            $.post("/sys/role/getRoles",{"orgId":data.value},function(data){
                var html="";
                var roles=data.roles;
                for(var i=0;i<roles.length;i++){
                    html+='<option value="'+roles[i].id+'">'+roles[i].name+'</option>';
                }
                $("#rid").html(html);
                form.render('select'); //刷新select选择框渲染
            },"json");
        });
    });
    function closeAll() {
        parent.layer.closeAll();
    }
</script>